/*
 * @Author: HZK
 * @Date: 2020-09-17 14:12:22
 * @LastEditTime: 2020-12-01 16:56:35
 * @LastEditors: hanfengmi
 * @Description: 
 */

const path = require('path');
const webpack = require('webpack');
const merge = require('webpack-merge');
const baseConfig = require('./webpack.base.js'); // 引用公共的配置

const devConfig = {
  mode: 'development', // 开发模式
  entry: path.join(__dirname, "../app.js"),
	output: {
		path: path.join(__dirname, "example"),
    filename: "[name].[hash].js", 
  },
  module: {
		rules: [
      {
        test: /\.css$/,
        use: ['style-loader',{
          loader:'css-loader',
          options: {
              modules: {
                  localIdentName: '[local]-[name]-[hash:base64:5]'
              },
            }
        },'postcss-loader'],
        exclude:[/node_modules/],
      },
      {
        test: /\.css$/,
        use: ['style-loader','css-loader'],
        exclude:[/src/],
      },
      {
        test:/\.less$/,
          use:['style-loader',{
            loader:'css-loader',
            options: {
                modules: {
                    localIdentName: '[local]-[name]-[hash:base64:5]'
                },
              }
        },'postcss-loader','less-loader'],
        exclude: /node_modules/
      },
    ]
  },
  plugins: [
    new webpack.DefinePlugin({
      "process.env.prod" : JSON.stringify('localhost')
    }),
  ],
	devServer: {
    compress: true,
    host: 'localhost', // webpack-dev-server启动时要指定ip，不能直接通过localhost启动，不指定会报错
    port: 3001, // 启动端口为 3001 的服务
    open: true, // 自动打开浏览器
    proxy: {
      '/api': {
        target: 'http://branch.yonyou.com',
        changeOrigin: true,
        pathRewrite: { '^/api' : '' },
      },
      '/up_service/': {
        target: 'http://branch.yonyou.com', // 代理接口
        changeOrigin: true,
        pathRewrite: {
          // '^/php': '/'    //代理的路径
        },
      },
      '/ServerApi': {
        target: 'http://branch.yonyou.com', // 代理接口
        changeOrigin: true,
        pathRewrite: {
          // '^/php': '/'    //代理的路径
        },
      }
    },
  },
};
module.exports = merge(devConfig, baseConfig); // 将baseConfig和devConfig合并为一个配置
